<template>
  <div class="app-container">
    <!-- 车辆违章 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="请选择工地" prop="constructionSiteId">
        <el-select v-model="queryParams.constructionSiteId" clearable placeholder="请选择工地">
          <el-option v-for="(v,index) in constructionSiteList" :key="index" :label="v.name" :value="v.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属省" prop="provinceCode">
        <el-select
          v-model="queryParams.provinceCode"
          clearable
          placeholder="请选择所属省"
          @change="provinceChange"
        >
          <el-option
            v-for="(v,index) in provinceList"
            :key="index"
            :label="v.provinceName"
            :value="v.provinceCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属市" prop="cityCode">
        <el-select
          v-model="queryParams.cityCode"
          clearable
          placeholder="请选择所属市"
          @change="cityChange"
        >
          <el-option
            v-for="(v,index) in cityList"
            :key="index"
            :label="v.cityName"
            :value="v.cityCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属县区" prop="areaCode">
        <el-select v-model="queryParams.areaCode" clearable placeholder="请选择区域">
          <el-option
            v-for="(v,index) in areaList"
            :key="index"
            :label="v.areaName"
            :value="v.areaCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" clearable placeholder="请选择审核状态">
          <el-option
            v-for="(v,index) in zfAuditStatusList"
            :key="index"
            :label="v.label"
            :value="v.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否阅读" prop="isRead">
        <el-select v-model="queryParams.isRead" clearable placeholder="请选择">
          <el-option label="已读" value="1"></el-option>
          <el-option label="未读" value="0"></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="是否处理" prop="isHandle">
        <el-select v-model="queryParams.isHandle" clearable placeholder="请选择">
          <el-option label="已处理" value="1"></el-option>
          <el-option label="未处理" value="0"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['violation:project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['violation:project:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['violation:project:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['violation:project:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      border
      fit
      highlight-current-row
      empty-text="暂无数据"
      v-loading="loading"
      :data="projectList"
      @selection-change="handleSelectionChange"
      show-overflow-tooltip="true"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="序号" align="center" prop="id" /> -->
      <el-table-column label="工地名称" align="center" prop="constructionSiteName" width="180" >
        <!-- <template slot-scope="scope">
          <el-link type="primary" @click="detail(scope.row)">
            {{
            scope.row.constructionSiteName
            }}
          </el-link>
        </template> -->
      </el-table-column>
      <el-table-column label="所属省" align="center" prop="provinceName" width="80" />
      <el-table-column label="所属市" align="center" prop="cityName" width="80" />
      <el-table-column label="所属县区" align="center" prop="areaName" width="80" />
      <el-table-column
        label="违章行为类型"
        align="center"
        prop="violationType"
        width="200"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_violation_type" :value="scope.row.violationType" />
        </template>
      </el-table-column>
      <el-table-column
        label="违章条例"
        align="center"
        prop="regulationConfig.regulationsTitle"
        width="200"
        :show-overflow-tooltip="true"
      />
      <!--      <el-table-column label="标记处理意见ID" align="center" prop="resolutionId" />-->
      <el-table-column label="违章说明备注" align="center" prop="remark" width="180" />
      <el-table-column label="违章地点" align="center" prop="locAddress" width="180"  />
      <el-table-column label="违章时间" align="center" prop="createTime" width="180"  />
      <el-table-column label="审核不通过原因" align="center" prop="auditReason" width="120" />
      <el-table-column label="执法人员姓名" align="center" prop="lawerUserName" width="120" />
      <!--      <el-table-column label="是否阅读，0-未读，1-已读" align="center" prop="isRead" >-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.read_status" :value="scope.row.isRead"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="违章金额" align="center">
        <template slot-scope="scope">￥{{scope.row.violationAmount}}</template>
      </el-table-column>
      <!-- <el-table-column label="是否处理" align="center" prop="isHandle">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.handle_status" :value="scope.row.isHandle" />
        </template>
      </el-table-column> -->
      <!--      <el-table-column label="整改现场照片" align="center" prop="handleImgUrl" >-->
      <!--        <template slot-scope="scope">-->
      <!--          <image-preview :src="scope.row.handleImgUrl" :width="50" :height="50"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="整改说明" align="center" prop="handleContent" />-->
      <!--      <el-table-column label="工地负责单位ID" align="center" prop="construtionUnitId" />-->
      <!--      <el-table-column label="执法人员ID" align="center" prop="lawerUserId" />-->
      <!--      <el-table-column label="操作人" align="center" prop="auditUserId" />-->
      <!--      <el-table-column label="图片地址,多个使用逗号隔开" align="center" prop="imageUrl" width="100">-->
      <!--        <template slot-scope="scope">-->
      <!--          <image-preview :src="scope.row.imageUrl" :width="50" :height="50"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="视频地址,多个使用逗号隔开" align="center" prop="videoUrl" width="100">-->
      <!--        <template slot-scope="scope">-->
      <!--          <image-preview :src="scope.row.videoUrl" :width="50" :height="50"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->

      <el-table-column label="状态" align="center" prop="auditStatus" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.normal_audit_status" :value="scope.row.auditStatus" />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="230"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['violation:project:edit']"
          >修改</el-button> -->
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['violation:project:remove']"
          >删除</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDesc(scope.row)"
            v-hasPermi="['modules:company:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleAudit(scope.row)"
            v-if="scope.row.auditStatus==0"
            v-hasPermi="['violation:project:remove']"
          >审核</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleCorrection(scope.row)"
            v-if="scope.row.auditStatus==1"
            v-hasPermi="['violation:project:remove']"
          >整改</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目违章上报信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" class="fillUpForm" label-width="120px">
        
        <el-row>
          <el-col :span="8">
            <el-form-item label="项目" prop="constructionSiteId">
              <el-select
                :disabled="title == descTitle"
                v-model="form.constructionSiteId"
                clearable
                :placeholder="title == descTitle?'':'工地名称'"
                @change="constructionSiteChange"
              >
                <el-option
                  v-for="(v,index) in constructionSiteList"
                  :key="index"
                  :label="v.name"
                  :value="v.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="违章行为" prop="violationType">
              <el-select :disabled="title == descTitle" v-model="form.violationType" clearable :placeholder="title == descTitle?'':'请选择违章行为'">
                <el-option
                  v-for="(v,index) in dict.type.project_violation_type"
                  :key="index"
                  :label="v.label"
                  :value="v.value"
                ></el-option>
              </el-select>
              
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="违章条例" prop="resolutionId">
              <el-input v-if="form.regulationConfig" :disabled="title == descTitle" v-model="form.regulationConfig.regulationsTitle" :placeholder="title == descTitle?'':'请输入违章地点'" />
              <el-select v-else :disabled="title == descTitle" v-model="form.resolutionId" clearable :placeholder="title == descTitle?'':'请选择违章条例'">
                <el-option
                  v-for="(v,index) in regulationList"
                  :key="index"
                  :label="v.regulationsTitle"
                  :value="v.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="所属省" prop="provinceCode">
              <el-select
                :disabled="title == descTitle"
                v-model="form.provinceCode"
                clearable
                :placeholder="title == descTitle?'':'请选择省份'"
                @change="formProvinceChange"
              >
                <el-option
                  v-for="(v,index) in provinceList"
                  :key="index"
                  :label="v.provinceName"
                  :value="v.provinceCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属市" prop="cityCode">
              <el-select
                :disabled="title == descTitle"
                v-model="form.cityCode"
                clearable
                :placeholder="title == descTitle?'':'请选择城市'"
                @change="formCityChange"
              >
                <el-option
                  v-for="(v,index) in cityListForm"
                  :key="index"
                  :label="v.cityName"
                  :value="v.cityCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属区县" prop="areaCode">
              <el-select
                :disabled="title == descTitle"
                v-model="form.areaCode"
                clearable
                :placeholder="title == descTitle?'':'请选择区域'"
                @change="formAreaChange"
              >
                <el-option
                  v-for="(v,index) in areaListForm"
                  :key="index"
                  :label="v.areaName"
                  :value="v.areaCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="执法人姓名" prop="lawerUserName">
              <el-input :disabled="title == descTitle" v-model="form.lawerUserName" :placeholder="title == descTitle?'':'请输入执法人姓名'" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="违章地点" prop="locAddress">
              <el-input :disabled="title == descTitle" v-model="form.locAddress" :placeholder="title == descTitle?'':'请输入违章地点'" />
            </el-form-item>
          </el-col>
          <!--        <el-form-item label="整改现场照片" prop="handleImgUrl">-->
          <!--          <image-upload v-model="form.handleImgUrl"/>-->
          <!--        </el-form-item>-->
          <!--        <el-form-item label="整改说明">-->
          <!--          <el-input v-model="form.handleContent" type="textarea" placeholder="请输入内容" />-->
          <!--        </el-form-item>-->
          <el-col :span="8">
            <el-form-item label="违章金额" prop="violationAmount">
              <el-input
                :disabled="title == descTitle"
                v-model="form.violationAmount"
                :placeholder="title == descTitle?'':'请输入违章金额'"
                type="number"
                step="0.1"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="违章说明备注" prop="remark">
              <el-input :disabled="title == descTitle" v-model="form.remark" type="textarea" :placeholder="title == descTitle?'':'请输入内容'" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="现场图片" prop="imageUrl">
              <image-upload v-if="title != descTitle" v-model="form.imageUrl" />
              <!-- <imgShow  v-if="title == descTitle" v-model="form.imageUrl" /> -->
              <div v-if="title == descTitle" style="width: 100%; display: flex;">
                <div style="display: inline-block; margin: 0 8px 8px 0; border: 1px solid #c0ccda; border-radius: 6px;" v-for="(item, i) in form.imageUrl" :key="i">
                  <el-image
                    @click="handlePictureCardPreview(item)"
                    style="width: 148px; height: 148px"
                    :src="item.url"
                    fit="cover"></el-image>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="现场视频" prop="videoUrl">
              <file-upload v-if="title != descTitle" v-model="form.videoUrl" />
              <el-video
                v-if="form.videoUrl && title != descTitle"
                :src="form.videoUrl"
                :autoplay="false"
                :loop="false"
                :controls="true"
                width="640"
                height="360"
              ></el-video>
              <!-- {{form.videoUrl}} -->
              <video v-if="title == descTitle && form.videoUrl" width="320" height="240" controls>
                <!-- <source :src="form.videoUrl" type="video/mp4" /> -->
                <source :src="form.videoUrl" type="video/mp4" />
              </video>
            </el-form-item>
          </el-col>
          
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="title != descTitle"  type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改项目违章上报信息对话框 -->
    <el-dialog title="违章审核" :visible.sync="auditOpen" width="500px" append-to-body>
      <el-form ref="auditForm" :model="auditForm" :rules="auditRules" label-width="80px">
        <el-form-item label="审核状态" prop="auditStatus">
          <el-select v-model="auditForm.auditStatus" clearable placeholder="请选择审核状态">
            <!--            <el-option-->
            <!--              v-for="(v,index) in dict.type.normal_audit_status"-->
            <!--              :key="index"-->
            <!--              :label="v.label"-->
            <!--              :value="v.value"-->
            <!--            ></el-option>-->
            <el-option label="审核通过" value="2"></el-option>
            <el-option label="审核不通过" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核说明" prop="reason">
          <el-input v-model="auditForm.reason" type="textarea" placeholder="请输入审核说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAuditForm">确 定</el-button>
        <el-button @click="cancelAudit">取 消</el-button>
      </div>
    </el-dialog>

    
    <el-dialog
      :visible.sync="dialogVisible"
      title="预览"
      width="800"
      append-to-body
    >
      <img
        :src="dialogImageUrl"
        style="display: block; max-width: 100%; margin: 0 auto"
      />
    </el-dialog>

    <!--    <el-dialog title="违章详情" :visible.sync="visibleDetail" width="500px" append-to-body>-->
    <!--      <div style="padding: 20px 30px">-->
    <!--        <el-descriptions class="descriptions" title="违章详情" :column="3" border>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">工地名称</template>{{ projectReport.constructionSiteName }}-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">违章地点</template>{{ projectReport.address }}-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">-->
    <!--              违章行为类型-->
    <!--            </template>-->
    <!--            <el-tag type="success">-->
    <!--              <dict-tag :options="dict.type.project_violation_type" :value="projectReport.violationType"/>-->
    <!--            </el-tag>-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">违章条例</template>{{ projectReport.regulationConfig.regulationsTitle }}-->
    <!--          </el-descriptions-item>-->

    <!--          &lt;!&ndash;      <el-descriptions-item>&ndash;&gt;-->
    <!--          &lt;!&ndash;        <template slot="label">&ndash;&gt;-->
    <!--          &lt;!&ndash;          违章条例&ndash;&gt;-->
    <!--          &lt;!&ndash;        </template>&ndash;&gt;-->
    <!--          &lt;!&ndash;        <el-tag type="success">&ndash;&gt;-->
    <!--          &lt;!&ndash;          <dict-tag :options="dict.type.nursing_label" :value="nursing.nursingLabel"/>&ndash;&gt;-->
    <!--          &lt;!&ndash;        </el-tag>&ndash;&gt;-->
    <!--          &lt;!&ndash;      </el-descriptions-item>&ndash;&gt;-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">违章说明</template>{{ projectReport.remark }}-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">-->
    <!--              审核状态-->
    <!--            </template>-->
    <!--            <el-tag type="success">-->
    <!--              <dict-tag :options="dict.type.normal_audit_status" :value="projectReport.auditStatus"/>-->
    <!--            </el-tag>-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">现场图片</template>-->
    <!--            <image-preview :src="projectReport.imageUrl" :width="50" :height="50"/>-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">现场视频</template>-->
    <!--            <video :src="projectReport.videoUrl" :width="50" :height="50"/>-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label">查处时间</template>{{ nursing.roomSize }}-->
    <!--          </el-descriptions-item>-->
    <!--          <el-descriptions-item>-->
    <!--            <template slot="label"></template>{{ nursing.floorSpace }}-->
    <!--          </el-descriptions-item>-->
    <!--        </el-descriptions>-->
    <!--      </div>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import {
  pageProject,
  getProject,
  delProject,
  addProject,
  updateProject,
  auditProject
} from "@/api/violation/project";
import sysConstant from "@/utils/sysConstant";
import { provinceList, cityList, areaList } from "@/api/region/region";
import { listSite } from "@/api/construction/site";
import { listRegulation } from "@/api/manger/regulation";


// import imgShow from "@/components/imgShow/index";

export default {
  name: "Project",
  dicts: [
    "project_violation_type",
    "normal_audit_status",
    "read_status",
    "handle_status"
  ],
  // components: { imgShow },
  data() {
    return {
      projectReport: {},
      visibleDetail: false,
      auditOpen: false,
      auditForm: {
        id: null,
        reason: null,
        auditStatus: null
      },
      auditRules: {
        auditStatus: [
          { required: true, message: "请选择审核状态", trigger: "blur" }
        ],
        id: [
          { required: true, message: "审核数据编号不能为空", trigger: "blur" }
        ]
      },
      provinceList: [],
      cityList: [],
      areaList: [],
      //工地信息
      constructionSiteList: [],
      //违章条例
      regulationList: [],
      //违章行为
      zfAuditStatusList: sysConstant.VIOLATION_AUDIT_STATUS_LIST,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目违章上报信息表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        constructionSiteId: null,
        constructionViolationId: null,
        resolutionId: null,
        violationType: null,
        constructionSiteName: null,
        // provinceCode: "130000",
        provinceCode: "",
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        townName: null,
        townCode: null,
        auditStatus: null,
        address: null,
        isRead: null,
        isHandle: null,
        status: 0,
        handleImgUrl: null,
        handleContent: null,
        construtionUnitId: null,
        lawerUserId: null,
        auditReason: null,
        lawerUserName: null,
        auditUserId: null,
        imageUrl: null,
        videoUrl: null,
        violationAmount: null
      },
      // 表单参数
      form: {
        provinceCode: null,
        id: null,
        constructionSiteId: null,
        constructionViolationId: null,
        resolutionId: null,
        violationType: null,
        constructionSiteName: null,
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        townName: null,
        townCode: null,
        auditStatus: null,
        remark: null,
        address: null,
        isRead: null,
        isHandle: null,
        status: null,
        createTime: null,
        updateTime: null,
        handleImgUrl: null,
        handleContent: null,
        construtionUnitId: null,
        lawerUserId: null,
        auditReason: null,
        lawerUserName: null,
        auditUserId: null,
        imageUrl: null,
        videoUrl: null,
        violationAmount: null,
        reportNumber: null,
        lat: null,
        lon: null,
        locAddress: null
      },
      // 表单校验
      rules: {
        
        constructionSiteId: [
          { required: true, message: "驾驶员姓名不能为空", trigger: "blur" }
        ],
        violationType: [
          { required: true, message: "违章行为不能为空", trigger: "change" }
        ],
        resolutionId: [
          { required: true, message: "违章条例不能为空", trigger: "change" }
        ],
      },
      descTitle: '查看项目违章', // 详情标题

      
      dialogImageUrl: '',
      dialogVisible: false,

      
      cityListForm: [],
      areaListForm: [],
    };
  },
  created() {
    this.getList();
    this.initProvinceList();
    this.initCityList(this.queryParams.provinceCode);
    this.initConstructionSiteList();
    this.initRegulationList();
  },
  methods: {
    initConstructionSiteList() {
      listSite().then(response => {
        this.constructionSiteList = response.data;
      });
    },
    initRegulationList() {
      listRegulation({ type: 0, status: 0 }).then(response => {
        this.regulationList = response.data;
      });
    },
    initProvinceList() {
      provinceList().then(response => {
        this.provinceList = response.data;
      });
    },
    initCityList(v) {
      let obj = {
        provinceCode: v
      };
      cityList(obj).then(response => {
        this.cityList = response.data;
      });
    },
    initAreaList(v) {
      let obj = {
        cityCode: v
      };
      areaList(obj).then(response => {
        this.areaList = response.data;
      });
    },
    //省份选择的
    provinceChange(v) {
      this.initCityList(v);
      this.queryParams.cityCode = null;
      this.queryParams.areaCode = null;
    },
    //省份选择的
    formProvinceChange(v) {
      this.initCityList(v);
      var obj = {};
      obj = this.provinceList.find(function(item) {
        return item.provinceCode === v;
      });
      console.log("province");
      console.log(obj);
      this.form.provinceName = obj.provinceName;
      this.cityList = [];
      this.areaList = [];
    },
    cityChange(v) {
      this.initAreaList(v);
      this.queryParams.areaCode = null;
    },
    //城市选择的
    formCityChange(v) {
      this.initAreaList(v);
      var obj = {};
      obj = this.cityList.find(function(item) {
        return item.cityCode === v;
      });
      console.log("city");
      console.log(obj);
      this.form.cityName = obj.cityName;
      this.form.cityCode = v;
      this.areaList = [];
    },
    formAreaChange(v) {
      var obj = {};
      obj = this.areaList.find(function(item) {
        return item.areaCode === v;
      });
      console.log("area");
      console.log(obj);
      this.form.areaName = obj.areaName;
      this.form.areaCode = v;
    },
    constructionSiteChange(v) {
      var obj = {};
      obj = this.projectList.find(function(item) {
        return item.id === v;
      });
      console.log("site");
      console.log(obj);
      this.form.constructionSiteName = obj.name;
      this.form.constructionSiteId = v;
    },
    /** 查询项目违章上报信息列表 */
    getList() {
      this.loading = true;
      pageProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        constructionSiteId: null,
        constructionViolationId: null,
        resolutionId: null,
        violationType: null,
        constructionSiteName: null,
        provinceCode: null,
        provinceName: null,
        cityCode: null,
        cityName: null,
        areaCode: null,
        areaName: null,
        townName: null,
        townCode: null,
        auditStatus: null,
        remark: null,
        address: null,
        isRead: null,
        isHandle: null,
        status: null,
        createTime: null,
        updateTime: null,
        handleImgUrl: null,
        handleContent: null,
        construtionUnitId: null,
        lawerUserId: null,
        auditReason: null,
        lawerUserName: null,
        auditUserId: null,
        imageUrl: null,
        videoUrl: null,
        violationAmount: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增项目违章";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getProject(id).then(response => {
        this.form = response.data;
        this.form.constructionSiteId = String(this.form.constructionSiteId)
        this.form.violationType = String(this.form.violationType)
        
        this.open = true;
        this.title = "修改项目违章上报信息";
      });
    },
    /** 查询按钮操作 */
    handleDesc(row) {
      this.reset();
      const id = row.id || this.ids;
      getProject(id).then(response => {
        this.form = response.data;
        this.form.constructionSiteId = String(this.form.constructionSiteId)
        this.form.violationType = String(this.form.violationType)

        if(this.form.provinceCode){
          this.initCityListForm(this.form.provinceCode)
        }
        if(this.form.cityCode){
          this.initAreaListForm(this.form.cityCode)
        }

        let baseUploadUrl = process.env.VUE_APP_BASE_API
        // let baseUploadUrl = 'http://192.168.31.156:8808/'
        let getLast = baseUploadUrl[baseUploadUrl.length-1]
        console.log(getLast)
        if(getLast == '/'){
          baseUploadUrl = baseUploadUrl.slice(0, -1)
        }
        console.log(baseUploadUrl, 'baseUploadUrl')
        
        // 处理图片
        if(this.form.imageUrl){
           // 首先将值转为数组
           let list = Array.isArray(this.form.imageUrl) ? this.form.imageUrl : this.form.imageUrl.split(',');
          // 然后将数组转为对象数组
          let imgList = []
          imgList = list.map(item => {
            if (typeof item === "string") {
              if (item.indexOf('http') === -1) {
                  item = { name: item, url: baseUploadUrl + item };
              } else {
                  item = { name: item, url: item };
              }
            }
            return item;
          });
          console.log(imgList, 'imgList')
          this.form.imageUrl = imgList
        }

        // 处理视频链接
        if(this.form.videoUrl){
          // this.form.videoUrl = process.env.VUE_APP_BASE_API + this.form.videoUrl
          this.form.videoUrl = baseUploadUrl + this.form.videoUrl
        }
        
        this.open = true;
        this.title = this.descTitle;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    submitAuditForm() {
      this.handleAuditProject();
    },
    handleAuditProject() {
      this.$refs["auditForm"].validate(valid => {
        if (valid) {
          if (this.auditForm.id != null) {
            auditProject(this.auditForm).then(response => {
              this.$modal.msgSuccess("审核完成");
              this.auditOpen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除项目违章上报信息编号为"' + ids + '"的数据项？')
        .then(function() {
          return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "violation/project/export",
        {
          ...this.queryParams
        },
        `project_${new Date().getTime()}.xlsx`
      );
    },
    handleAudit(row) {
      this.auditForm.id = row.id;
      this.auditOpen = true;
    },
    cancelAudit() {
      this.auditForm.id = null;
      this.auditOpen = false;
    },
    handleCorrection() {},
    detail(row) {
      getProject(row.id).then(response => {
        this.projectReport = response.data;
        this.visibleDetail = true;
      });
    },

    
    // 预览
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },

    
    initCityListForm(v) {
      let obj = {
        provinceCode: v
      };
      cityList(obj).then(response => {
        this.cityListForm = response.data;
      });
    },
    
    initAreaListForm(v) {
      let obj = {
        cityCode: v
      };
      areaList(obj).then(response => {
        this.areaListForm = response.data;
      });
    },
  }
};
</script>


<style lang="scss" scoped>
  
  .fillUpForm {
    .el-input{
      width: 100%;
    }
    .el-select{
      width: 100%;
    }
  }

</style>